package com.ruoyi.hxf.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.hxf.domain.vo.PalmaryVo;
import com.ruoyi.hxf.domain.bo.PalmaryBo;
import com.ruoyi.hxf.service.IPalmaryService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学校介绍管理
 *
 * @author hxf
 * @date 2023-04-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/palmary/show")
public class PalmaryController extends BaseController {

    private final IPalmaryService iPalmaryService;

    /**
     * 查询学校介绍管理列表
     */
//    @SaCheckPermission("palmary:show:list")
    @GetMapping("/list")
    public TableDataInfo<PalmaryVo> list(PalmaryBo bo, PageQuery pageQuery) {
        return iPalmaryService.queryPageList(bo, pageQuery);
    }
    /**
     * 查询学校介绍管理列表
     */
    @GetMapping("/appList")
    public TableDataInfo<PalmaryVo> appList(PalmaryBo bo, PageQuery pageQuery) {
        return iPalmaryService.queryPageAppList(bo, pageQuery);
    }
    /**
     * 导出学校介绍管理列表
     */
//    @SaCheckPermission("palmary:show:export")
    @Log(title = "学校介绍管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PalmaryBo bo, HttpServletResponse response) {
        List<PalmaryVo> list = iPalmaryService.queryList(bo);
        ExcelUtil.exportExcel(list, "学校介绍管理", PalmaryVo.class, response);
    }

    /**
     * 获取学校介绍管理详细信息
     *
     * @param palmaryId 主键
     */
//    @SaCheckPermission("palmary:show:query")
    @GetMapping("/{palmaryId}")
    public R<PalmaryVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long palmaryId) {
        return R.ok(iPalmaryService.queryById(palmaryId));
    }

    /**
     * 新增学校介绍管理
     */
//    @SaCheckPermission("palmary:show:add")
    @Log(title = "学校介绍管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PalmaryBo bo) {
        return toAjax(iPalmaryService.insertByBo(bo));
    }

    /**
     * 修改学校介绍管理
     */
//    @SaCheckPermission("palmary:show:edit")
    @Log(title = "学校介绍管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PalmaryBo bo) {
        return toAjax(iPalmaryService.updateByBo(bo));
    }

    /**
     * 删除学校介绍管理
     *
     * @param palmaryIds 主键串
     */
//    @SaCheckPermission("palmary:show:remove")
    @Log(title = "学校介绍管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{palmaryIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] palmaryIds) {
        return toAjax(iPalmaryService.deleteWithValidByIds(Arrays.asList(palmaryIds), true));
    }
}
